package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.Admin_Feedbackresponse_Info;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Admin_feedbackresponseMapper {
    @Insert("INSERT INTO feedback_response (feedback_id, feedback_type, admin_id, question_id, response_type, " +
            "response_content, action_taken, before_content, after_content, status) " +
            "VALUES (#{feedbackId}, #{feedbackType}, #{adminId}, #{questionId}, #{responseType}, " +
            "#{responseContent}, #{actionTaken}, #{beforeContent}, #{afterContent}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "responseId")
    int addResponse(Admin_Feedbackresponse_Info response);

    @Update("UPDATE feedback_response SET " +
            "feedback_id = #{feedbackId}, " +
            "feedback_type = #{feedbackType}, " +
            "admin_id = #{adminId}, " +
            "question_id = #{questionId}, " +
            "response_type = #{responseType}, " +
            "response_content = #{responseContent}, " +
            "action_taken = #{actionTaken}, " +
            "before_content = #{beforeContent}, " +
            "after_content = #{afterContent}, " +
            "status = #{status} " +
            "WHERE response_id = #{responseId}")
    int updateResponse(Admin_Feedbackresponse_Info response);

    @Delete("DELETE FROM feedback_response WHERE response_id = #{response_id}")
    int deleteResponse(Integer response_id);

    @Select("SELECT * FROM feedback_response WHERE response_id = #{response_id}")
    Admin_Feedbackresponse_Info getResponseById(Integer response_id);

    @Select("SELECT * FROM feedback_response WHERE feedback_id = #{feedback_id}")
    List<Admin_Feedbackresponse_Info> getResponsesByFeedbackId(@Param("feedback_id") Integer feedback_id);

    @Select("SELECT * FROM feedback_response")
    List<Admin_Feedbackresponse_Info> findAllResponses();

    @Select("SELECT fr.*, f.content as feedback_content, u.username " +
            "FROM feedback_response fr " +
            "LEFT JOIN feedbacks f ON fr.feedback_id = f.feedback_id " +
            "LEFT JOIN users u ON f.user_id = u.user_id")
    List<Admin_Feedbackresponse_Info> findAllResponsesWithUser();

    @Select("SELECT COUNT(*) FROM feedback_response")
    int countAllResponses();
}